integrateMC                package:Montecarlo                R Documentation

Monte Carlo integration with graphical exhibition

Description:

	A function that evaluates the integral of a given mathematical function
	on the given closed interval using Monte Carlo integration.

Usage:

	integrateMC(x)
	#Default
	integrateMC(x, from = 0, to = 1, n = 10000, graphical = FALSE)

Arguments:

	func: function to be integrated, using the usual mathematical operators
	and basic functions in R (*, /, exp, ^, sin, cos, sqrt, etc), constants (any
	real number) and the variable x.

	from: the lesser endpoint of the integration interval.

	to: the greater endpoint of the integration interval.
	
	n: the number of random points generated and used in the simulation. More
	points provide a more precise result.

	graphical: boolean option for displaying the simulation. The function and the
	points in the simulation are exhibited in a graphic.

Details:
	
	Evaluates the integral of a one-variable function over a given interval.  Accepts
	any function using the four basic mathematical opperators (*, /, +, -) and
	basic functions in R, such as sin, cos, tan, sqrt and exp, as well as compositions
	of those. The function must have x as it's only variable.
	
	The integral is calculated based on the estimated probability of a random point
	being between the curve and the x-axis on the given interval. The function
	exhibits the estimate value of the integral and and error value. The precise
	value of the integral will be between the calculated + error and calculated - error.

Warning:

	For a number of points (n) of order of magnitude above 3 (1000 points), graphical
	is not reccomended, since the simulation will take a large amount of time.
	The function given must have x as it's only variable.

Author(s):

	Ana Carolina Ribeiro Gomez

References:

	Kalos, M. H., Whitlock, P. A., (2008) _Monte Carlo Methods_. Wiley-VCH, 77-106
	
	http://en.wikipedia.org/wiki/Monte_Carlo_integration

Examples:
	
	#simple calculation
	integrateMC(x^2 * sin(x+exp(2.4*x)))
	
	#graphical simulation
	integrateMC(3*x^2 + 4*x + 2, graphical = TRUE)
	
	#more precise estimate, with many points
	integrateMC(sin(x), from = 0, to = 2*pi, n = 1000000, graphical = FALSE)


